package code09.Bank;

/**
 * @ClassName CheckAccount
 * @Description TODO
 * @Author wuhn Email:1845979768@qq.com
 * @Date 2021/8/12 20:01
 * @Version 1.0
 */
public class CheckAccount extends Account{
    private double overdraft;

    public CheckAccount(int id,double balance,double annualInterestRate,double overdraft){
        super(id, balance, annualInterestRate);
        this.overdraft=overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    @Override
    public void withDraw(double amount) {
        if(getBalance()>=amount){
            super.withDraw(amount);
        }else if(overdraft>=amount-getBalance()){
            overdraft-=(amount-getBalance());
            setBalance(0);
        }else {
            System.out.println("超过可透支限额");
        }
    }
}
